<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2022-05-07
  Time: 10:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/main.css">
    <script src="js/jquery-1.8.3.js"></script>
    <script>
        $(function (){
            let msg = "${msg}"
            if(msg){
                alert(msg);
                <c:remove var="msg"></c:remove>
            }
        });
        function toAdd(){
            location.href='add.jsp';
        }

        function toUpdate(id){
            location.href='update.jsp?id='+id;
        }

        function toDelete(id){
            if(confirm("确定删除次学生信息吗？")){
                location.href='student?op=102&id='+id;
            }else {
                return;
            }
        }
    </script>
</head>
<body>
    <div id="container">
        <span class="simtitle">
            <h3>学生信息管理</h3>
        </span>
        <table>
            <tr>
                <td>姓名:<input type="text"></td>
                <td>
                    <button>搜索</button></td>
            </tr>
        </table>
        <span class="toolbar">
            <button onclick="toAdd()">添加</button>
        </span>
        <table id="dataTable">
            <tr>
                <th>
                    学号
                </th>
                <th>
                    姓名
                </th>
                <th>
                    生日
                </th>
                <th>
                    操作
                </th>
            </tr>
            <c:choose>
                <c:when test="${empty stus}">
                    <tr>
                        <td align="center" colspan="4">暂无数据</td>
                    </tr>
                </c:when>
                <c:otherwise>
                    <c:forEach items="${stus}" var="stu">
                        <tr>
                            <td>${stu.id}</td>
                            <td>${stu.name}</td>
                            <td>
                                <fmt:formatDate value="${stu.birthDate}" pattern="yyyy-MM-dd"></fmt:formatDate>
                            </td>
                            <td>
                                <button onclick="toUpdate(${stu.id})">修改</button>
                                <button onclick="toDelete(${stu.id})">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                </c:otherwise>
            </c:choose>
        </table>
    </div>
</body>
</html>
